/************************* (C) COPYRIGHT 2008 Domain **************************
 * File Name   : sys_arch.c                                                   *
 * Author      : Domain                                                       *
 * E-mail      : do.main@msn.com                                              *
 * Version     : 1.0                                                          *
 * Date        : 2008/6/26                                                    *
 * Description :                                                              *
 ******************************************************************************/

#include "lwip/debug.h"
#include "lwip/sys.h"
#include "lwip/opt.h"
#include "lwip/memp.h"

#include "stm32f10x_init.h"
#include "timer.h"

struct sys_timeouts lwip_system_timeouts; /* Default timeouts list for lwIP */

void
sys_init()
{
  stm32f10x_init();
  SystemTimerInit();
  lwip_system_timeouts.next = NULL;
}
/*-----------------------------------------------------------------------------------*/
struct sys_timeouts *
sys_arch_timeouts(void)
{
  return &lwip_system_timeouts;
}

/*-----------------------------------------------------------------------------------*/

u32_t
sys_jiffies(void)
{
	return GetSysTick();
}

void sys_clear_timeouts(void)
{
  struct sys_timeo *t, *next;
  t = lwip_system_timeouts.next;
  /*for (t = lwip_system_timeouts.next, prev_t = NULL; t != NULL; prev_t = t, t = t->next) 
  {
    if (prev_t == NULL)
      SysTimeOut->next = t->next;
    else
      prev_t->next = t->next;
	  t->h(t->arg);
    memp_free(MEMP_SYS_TIMEOUT, t);
  }*/
  while(t)
  {	  
    next = t->next;
    //sys_untimeout(t->h, t->arg);
    memp_free(MEMP_SYS_TIMEOUT, t);
    t = next;	
  }
  lwip_system_timeouts.next = NULL;
}

/************************* (C) COPYRIGHT 2008 Domain ******* END OF FILE ******/
